<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>工单</title>
    <link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>
	<style type="text/css">
    	.detail{
    		padding-right: 20px!important;
    	}
    	h5{color: #0062CC;}
    	.mui-navigate-right .mui-col-xs-8{
		    width: 62.666667%!important;
    	}
    	.mui-text-right input,.mui-text-right textarea{
    		border: 0;
    		font-size: 14px;
		    font-weight: 400;
		    color: #8f8f94;
    		margin-bottom: 0;
    		text-align: right;
    	}
    </style>
</head>

<body>
    <div class="mui-content">
		<ul class="mui-table-view mui-table-view-chevron">
			<li class="mui-table-view-cell detail">
				<div class="mui-table">
	                <div class="mui-table-cell mui-col-xs-4">
	                    <h5 class="mui-ellipsis">当前标准成本：</h5>
	                </div>
	                <div class="mui-table-cell mui-col-xs-8 mui-text-right">
	                    <span class="mui-h5" id="oldcost"></span>
	                </div>
	            </div>
			</li>
			<li class="mui-table-view-cell detail">
				<div class="mui-table">
	                <div class="mui-table-cell mui-col-xs-4">
	                    <h5 class="mui-ellipsis">调整标准成本：</h5>
	                </div>
	                <div class="mui-table-cell mui-col-xs-8 mui-text-right">
	                    <input type="text" placeholder="请输入要调整的成本" name="" id="newcost" value="" />
	                </div>
	            </div>
           </li>
           <li class="mui-table-view-cell detail">
				<div class="mui-table">
	                <div class="mui-table-cell mui-col-xs-4">
	                    <h5 class="mui-ellipsis">调整原因：</h5>
	                </div>
	                <div class="mui-table-cell mui-col-xs-8 mui-text-right">
	                    <input type="text" placeholder="请输入要调整的原因" name="" id="memo" value="" />
	                </div>
	            </div>
           </li>
		</ul>
		<div class="mui-content" id="ordrListsContent">
			<script type="text/template" id="itemslist">
			{{each datas as item i}}
			<div class="mui-card">
				<ul class="mui-table-view mui-table-view-chevron">
					<li class="mui-table-view-cell mui-collapse">
						<a class="mui-navigate-right" href="#">当前标准成本：{{item.newcost}}
							<span class="mui-badge mui-badge-inverted">调整人:{{item.enterby}}</span>
						</a>
						<ul class="mui-table-view mui-table-view-chevron">
							<li class="mui-table-view-cell">调整前成本：{{item.oldcost}}</li>
							<li class="mui-table-view-cell">调整时间：{{item.transdate}}</li>
							<li class="mui-table-view-cell">调整原因：{{item.memo}}</li>
						</ul>
					</li>
				</ul>
			</div>
			{{/each}}
			</script>
		</div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script src="../script/mui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../script/common.js" type="text/javascript" charset="utf-8"></script>
<script src="../script/template.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
	var oldcost;
	apiready = function () {
		onLoadData(curPage,false);
		scrollToBottomHandler(function() {
			if (!loadEnd) { // 没有结束时继续加载
				curPage++;
				onLoadData(curPage,true);
			} else { // 告诉到底了
				Toast('到底了');
			}
		})
		Refresh(function() {
			loadEnd = false;
			curPage = 1;
			onLoadData(curPage,false);
		});
		api.parseTapmode();
		api.addEventListener({
            name: 'navitembtn'
        }, function(ret, err) {
            if (ret.index == 0) {
                if ($api.val($api.byId('newcost')) == '') {
                    Toast('请输入标准成本！');
                    return
                }
                if ($api.val($api.byId('memo')) == '') {
                    Toast('请输入调整原因！');
                    return
                }
                ajaxrd("saveStandardCost", {
                	itemnum: api.pageParam.itemnum,
                	location: api.pageParam.locations,
                	oldcost: oldcost,
                	newcost:$api.val($api.byId('newcost')),
                	memo:$api.val($api.byId('memo'))
                }, function(ret, err) {
                    api.sendEvent({
                        name: 'refersh',
                        extra: {
                            isrefersh: 'yes'
                        }
                    });
                    Toast('操作成功！');
                    setTimeout(function() {
                        api.closeWin();
                    }, 500)
                })
            } else { //扫码

            }
        });
	}
	function onLoadData (page,load) {
		ajaxrd("queryStandardList", {
			itemnum: api.pageParam.itemnum,
			pageNo: curPage,
			pageSize: 10
		}, function(ret, err) {
	      api.refreshHeaderLoadDone();
	      AddData('itemslist','ordrListsContent',ret.list,load);
	      if (ret.list.length < 10) {
	        loadEnd = true
	      }
		})
		ajaxrd("queryStandardCost", {
			itemnum: api.pageParam.itemnum,
			location: api.pageParam.locations
		}, function(ret, err) {
			$api.text($api.byId('oldcost'),ret.standarCost);
			oldcost = ret.standarCost;
		})
	}
</script>

</html>
